#pragma once

//#include <d3dx9.h>

#define MAX_FONT	(10)

#include "RectElement.h"
#include "TextElement.h"

class PFMEngine
{
private:
	struct TEX_INFO
	{
		std::string			strPath;
		LPDIRECT3DTEXTURE9	pTexture;
		int					nRefCnt;
	};

public:
	PFMEngine();
	~PFMEngine();

public:
	bool			Create(void* hWnd, DWORD Width = 800, DWORD Height = 600, bool bIsFullScreen = false);
	void			Release();
	void			Render();

	void			SetRenderState(DWORD dwStateType, DWORD dwValue);
	void			SetupMatrices();

	RectElement*	CreateRect(const char* pPath);
	void			ReleaseRect(RectElement* pRect);

	TextElement*	CreateText(int nFontIndex);
	void			ReleaseText(TextElement* pText);

	void			AddDrawElement(DrawElement* pDraw)		{ m_DrawElementList.push_back(pDraw); }

	void			ChangeRectTexture(RectElement* pRect, const char* pPath);

	void			SetFont( int nFontIndex , int nHeight , BOOL bBold , LPCTSTR pFacename , DWORD dwColor = 0xFFFFFFFF , int shadow = 0);
	void			DrawText( int nFontIndex , const char* str , int x , int y , DWORD dwColor = 0 ); 

	void			SetUseNonPow2Tex(BOOL bSet)				{ m_bUseNonPow2Tex = bSet; }

private:
	void			CreateTexture( const char* pPath, LPDIRECT3DTEXTURE9& pTexture);
	void			ReleaseTexture(LPDIRECT3DTEXTURE9 pTexture);

private:
	LPDIRECT3D9         		m_pD3D;
	LPDIRECT3DDEVICE9   		m_pd3dDevice;

	LPD3DXFONT					m_pFont[MAX_FONT];
	D3DXCOLOR					m_fontColor[MAX_FONT];
	int							m_fontShadow[MAX_FONT];	

	float						m_fScreenWidth;
	float						m_fScreenHeight;

	BOOL						m_bUseNonPow2Tex;

	std::vector<TEX_INFO>		m_TexInfoList;
	std::vector<RectElement* >	m_RectElementList;
	std::vector<TextElement* >	m_TextElementList;
	std::vector<DrawElement* >	m_DrawElementList;
};

PFMEngine& GetPFMEngine();